<?php
//No direct access to this file should be called by Joomla
defined('_JEXEC') or die('Restricted Access');
//import joomla controller library
jimport('joomla.application.component.controller');

class TintucController extends JControllerLegacy
{
    function __construct($config = array())
    {
		// Article frontpage Editor pagebreak proxying:
		if (JRequest::getCmd('view') === 'article' && JRequest::getCmd('layout') === 'pagebreak') {
			$config['base_path'] = JPATH_COMPONENT_ADMINISTRATOR;
		}
		// Article frontpage Editor article proxying:
		elseif(JRequest::getCmd('view') === 'articles' && JRequest::getCmd('layout') === 'modal') {
			JHtml::_('stylesheet','system/adminlist.css', array(), true);
			$config['base_path'] = JPATH_COMPONENT_ADMINISTRATOR;
		}
		parent::__construct($config);
    }
	function tintuc(){
		JRequest::setVar('view', 'tintuc');
		$model = $this->getModel( 'tintuc' );
		$this->display();
	}
    function chitiet()
    {
		$model = $this->getModel( 'tintuc' );
		$app = JFactory::getApplication();
		$this->document = JFactory::getDocument();
		
		// $catID = JRequest::getVar('id',20);
		$catID = $model->getCatID();
		$subID = JRequest::getVar('Subid',0);
		$option = JRequest::getVar('option',0);

		$itemid = JRequest::getVar('Itemid',0);
		$categories = JCategories::getInstance('Content');
		$_parent = $categories->get((int) $catID);
		$sitename = $app->getCfg('sitename');
		$title = $this->document->getTitle();
				
		if(is_object($_parent))
		{
			$_items = $_parent->getChildren(false);
			if(isset($_items[0]) && empty($subID))
				$subID = $_items[0]->id;
		}
		else
		{
			$this->_items = false;
		}
		// $prefix = "Itemid=$itemid&";
		// $articles = $model->getItems($subID,1,$prefix);
		// $items = $data['rows'];
		JRequest::setVar('view', 'chitiet');
	    $article_id= JRequest::getVar('article_id');
		
	    $data = $model->getItem($article_id,$subID);
		$data['subID'] = $subID;
		$data['_items'] = $_items;
		$data['sitename'] = $sitename;
		$data['title'] = $title;
		$data['option'] = $option;
		$data['itemID'] = $itemid;
		JRequest::setVar('data',$data);
		$this->display();
    }

}
?>